package com.dwms.utils;

import com.dwms.enums.CacheGroup;
import com.dwms.enums.RedisType;
import com.dwms.service.RedisService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @author : WH
 * @date : 2025-08-11 20:36
 * @description : Redis工具类
 */
@Component
public class RedisUtils {

    private static RedisUtils redisUtils;
    @Resource
    private RedisService redisService;

    @PostConstruct
    public void init () {
        redisUtils = this;
        redisUtils.redisService = redisService;
    }

    public static boolean setnx(String sign) {
        if (StringUtils.isEmpty(sign)) {
            return false;
        }
        Long success = redisUtils.redisService.setnx(RedisType.COMMON_CACHE, CacheGroup.SIGN_CACHE, sign, System.currentTimeMillis() + "");
        return success > 0;
    }

    /**
     * 删除
     **/
    public static boolean delete(String appSign) {
        if (org.apache.commons.lang.StringUtils.isEmpty(appSign)) {
            return false;
        }
        Long exists = redisUtils.redisService.del(RedisType.COMMON_CACHE, CacheGroup.SIGN_CACHE, appSign);
        return exists > 0;
    }


}
